home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / ByteArrayOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  1.7 KB  |  80 lines

  1. package java.io;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class ByteArrayOutputStream extends OutputStream {
  6.    protected byte[] buf;
  7.    protected int count;
  8.  
  9.    public ByteArrayOutputStream() {
  10.       this(32);
  11.    }
  12.  
  13.    public ByteArrayOutputStream(int var1) {
  14.       if (var1 < 0) {
  15.          throw new IllegalArgumentException("Negative initial size: " + var1);
  16.       } else {
  17.          this.buf = new byte[var1];
  18.       }
  19.    }
  20.  
  21.    public synchronized void write(int var1) {
  22.       int var2 = this.count + 1;
  23.       if (var2 > this.buf.length) {
  24.          this.buf = Arrays.copyOf(this.buf, Math.max(this.buf.length << 1, var2));
  25.       }
  26.  
  27.       this.buf[this.count] = (byte)var1;
  28.       this.count = var2;
  29.    }
  30.  
  31.    public synchronized void write(byte[] var1, int var2, int var3) {
  32.       if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
  33.          if (var3 != 0) {
  34.             int var4 = this.count + var3;
  35.             if (var4 > this.buf.length) {
  36.                this.buf = Arrays.copyOf(this.buf, Math.max(this.buf.length << 1, var4));
  37.             }
  38.  
  39.             System.arraycopy(var1, var2, this.buf, this.count, var3);
  40.             this.count = var4;
  41.          }
  42.       } else {
  43.          throw new IndexOutOfBoundsException();
  44.       }
  45.    }
  46.  
  47.    public synchronized void writeTo(OutputStream var1) throws IOException {
  48.       var1.write(this.buf, 0, this.count);
  49.    }
  50.  
  51.    public synchronized void reset() {
  52.       this.count = 0;
  53.    }
  54.  
  55.    public synchronized byte[] toByteArray() {
  56.       return Arrays.copyOf(this.buf, this.count);
  57.    }
  58.  
  59.    public synchronized int size() {
  60.       return this.count;
  61.    }
  62.  
  63.    public synchronized String toString() {
  64.       return new String(this.buf, 0, this.count);
  65.    }
  66.  
  67.    public synchronized String toString(String var1) throws UnsupportedEncodingException {
  68.       return new String(this.buf, 0, this.count, var1);
  69.    }
  70.  
  71.    /** @deprecated */
  72.    @Deprecated
  73.    public synchronized String toString(int var1) {
  74.       return new String(this.buf, var1, 0, this.count);
  75.    }
  76.  
  77.    public void close() throws IOException {
  78.    }
  79. }
  80.